package com.hzy.fivepalace.wx.controller.api;


import com.hzy.fivepalace.common.util.JacksonUtil;
import com.hzy.fivepalace.common.util.ResponseUtil;
import com.hzy.fivepalace.common.util.TableDataInfo;
import com.hzy.fivepalace.wx.annotation.LoginUser;
import com.hzy.fivepalace.wx.controller.base.BaseController;
import com.hzy.fivepalace.wx.service.WxGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户收藏控制层
 */
@RestController
@RequestMapping("/wx/collection")
@Validated
@Api(tags = "用户收藏")
public class WxCollectFreshController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(WxCollectFreshController.class);

    @Autowired
    private WxGoodsService wxGoodsService;

    /**
     * 用户收藏列表
     *
     * @param userId 用户ID
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "用户收藏列表")
    public TableDataInfo list(@LoginUser @ApiParam(hidden = true) Integer userId,
                              @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer page,
                              @ApiParam(value = "分页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer size) {

        return wxGoodsService.getUserCollectionList(page,size,userId);
    }

    /**
     * 用户收藏添加或删除
     * <p>
     * 如果商品没有收藏，则添加收藏；如果商品已经收藏，则删除收藏状态。
     *
     * @param userId
     * @param body   请求内容，{'goodsId':'1'}
     * @return
     */
    @PostMapping("/addordelete")
    @ApiOperation(value = "用户收藏添加或删除")
    public Object addordelete(@LoginUser @ApiParam(hidden = true) Integer userId, @ApiParam(value = "{'goodsId':'1'}") @RequestBody String body) {

        return wxGoodsService.addordeleteCollection(userId,JacksonUtil.parseInteger(body, "goodsId"));
    }


}
